home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-21 | 3.2 KB | 93 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWClaInf.cpp
- // Release Version: $ 1.0d1 $
- //
- // Creation Date: 3/28/94
- //
- // Copyright: © 1994 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWCLAINF_H
- #include "FWClaInf.h"
- #endif
-
- #ifndef FWPRIDEB_H
- #include "FWPriDeb.h"
- #endif
-
- #pragma segment FW_ClassInfo
-
- //========================================================================================
- // CLASS FW_CClassInfo
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CClassInfo::FW_CClassInfo
- //----------------------------------------------------------------------------------------
- FW_CClassInfo::FW_CClassInfo(const char *const className,
- size_t instanceSize,
- FW_ClassReference const *ancestors) :
- fClassName(className),
- fInstanceSize(instanceSize),
- fAncestors(ancestors)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CClassInfo::~FW_CClassInfo
- //----------------------------------------------------------------------------------------
-
- FW_CClassInfo::~FW_CClassInfo()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CClassInfo::IsKindOf
- //----------------------------------------------------------------------------------------
-
- // (MLH) ??? - We should consider a cache scheme or a preporcessor calculation
- // What we really want is a list of all the classes between this and
- // the root. This knowledge is known at compile time. For the runtime
- // cache case, instead of recursively calling this routine, call a routine
- // that builds the list and stores it in a cache.
- //
- // The list is simply a vector of classinfo pointers and a count. It is much
- // faster to scan one vector then to recursively call IsKindOf.
- //
- // (JEL) ??? - I don't agree with the above. In order to flatten everything out
- // into a vectors, we would have to duplicate a lot of data. Suppose we have two
- // classes X and Y, that each are derived from a deep hierarchy A -> B -> C. To
- // flatten into vectors, we would need two vectors [A,B,C,X] and [A,B,C,Y], duplicating
- // the data [A,B,C]. I don't think it makes sense to do tradeoff space for speed.
- // In some specific uses it will make sense to cache, but I don't think that belongs
- // here. Perhaps we should take the effort to rewrite this algorithm so that it doesn't
- // use this kind of direct recursion, by writing a loop that manipulates an an internal
- // stack that contains the state of the search, but I think that is overkill without
- // evidence from testing that this function is a bottleneck.
-
- FW_Boolean FW_CClassInfo::IsKindOf(FW_ClassReference aBaseClass) const
- {
- FW_Boolean result = FALSE;
-
- if (aBaseClass == this)
- result = TRUE;
- else
- {
- FW_ClassReference const *ancestors = fAncestors;
-
- while (*ancestors != 0)
- {
- if ((*ancestors)->IsKindOf(aBaseClass))
- {
- result = TRUE;
- break;
- }
- ancestors++;
- }
- }
- return result;
- }
-
-